package com.gofun.framework.core.property;

import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.gofun.framework.core.utils.DateUtils;



public class CustomDateEditor extends PropertyEditorSupport {
	
	private Log log = LogFactory.getLog(getClass());
	
	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		Date date;
		String pattern = DateUtils.DATE;
		if(text.contains(":"))
			pattern = DateUtils.DATE_HH_MM_SS;
		try {
			date = DateUtils.parseByPattern(text, pattern);
			setValue(date);
			return;
		} catch (ParseException e1) {
			log.error("解析java.util.Date类型属性时发生异常,未知的日期格式,date:" + text,e1);
		}
	}

}
